import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import vuexpersist from "vuex-persist"

export default new Vuex.Store({
  state: {
    list: [
      {
        ck: 0,
        count: "13213131",
      },
    ],
    sc: 1,
    qx: false,
  },
  mutations: {
    add(state, item) {
      state.list.push({
        ck: 0,
        count: item,
      });
      state.qx=false
    },
    up(state, index) {
      if (state.list[index].ck == 0) {
        state.sc = 0
        state.list[index].ck = 1;
      } else {
        state.sc = 1
        state.list[index].ck = 0;
      }
    },
    ckall(state) {
      if (state.qx == false) {
        state.qx=true
        state.sc = 0
        state.list.forEach(item => {
          item.ck = 1
        })
        state.list=state.list
      } else if (state.qx == true) {
        state.qx = false
        state.sc = 1
        state.list.forEach(item => {
          item.ck = 0
        })
      }
    },
    remove(state) {
      var num=[]
      state.list.forEach((item, index) => {
        if (item.ck == 1) {
          num.push(item)
        }
      })
      num.forEach(res => {
        state.list.forEach((re,index) => {
          if (res.count == re.count) {
            state.list.splice(index,1)
          }
        })
      })
    },
    rem(state, index) {
      state.list.splice(index,1)
    }
  },
  actions: {
  },
  modules: {
  },
 plugins:[
    new vuexpersist({
    storage:window.localStorage,
  }).plugin,
],
})
